package org.rsbot.event.impl;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Polygon;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.HashMap;
import org.rsbot.bot.Bot;
import org.rsbot.event.listeners.PaintListener;
import org.rsbot.script.methods.GroundItems;
import org.rsbot.script.methods.MethodContext;
import org.rsbot.script.methods.NPCs;
import org.rsbot.script.methods.Objects;
import org.rsbot.script.methods.Players;
import org.rsbot.script.wrappers.RSCharacter;
import org.rsbot.script.wrappers.RSGroundItem;
import org.rsbot.script.wrappers.RSModel;
import org.rsbot.script.wrappers.RSObject;
import org.rsbot.script.wrappers.RSObject.Type;

public class DrawModel
  implements PaintListener, MouseListener
{
  private static final HashMap<RSObject.Type, Color> color_map = new HashMap();
  private static final String[] WORD_LIST;
  private static boolean[] Click;
  private MethodContext ctx;

  public DrawModel(Bot paramBot)
  {
    this.ctx = paramBot.getMethodContext();
  }

  public void onRepaint(Graphics paramGraphics) {
    DrawRect(paramGraphics);
    Object localObject2;
    RSModel localRSModel;
    Polygon localPolygon;
    if (Click[0] != 0)
      for (localObject2 : this.ctx.objects.getAll()) {
        localRSModel = localObject2.getModel();
        if (localRSModel != null) {
          paramGraphics.setColor((Color)color_map.get(localObject2.getType()));
          for (localPolygon : localRSModel.getTriangles()) {
            paramGraphics.drawPolygon(localPolygon);
          }
          paramGraphics.setColor(Color.GREEN);
          ??? = localRSModel.getPoint();
          paramGraphics.fillOval(((Point)???).x - 1, ((Point)???).y - 1, 2, 2);
        }
      }
    if (Click[1] != 0) {
      for (localObject2 : this.ctx.players.getAll()) {
        localRSModel = localObject2.getModel();
        if (localRSModel != null) {
          paramGraphics.setColor(Color.RED);
          for (localPolygon : localRSModel.getTriangles())
            paramGraphics.drawPolygon(localPolygon);
        }
      }
    }
    if (Click[2] != 0) {
      for (localObject2 : this.ctx.npcs.getAll()) {
        localRSModel = localObject2.getModel();
        if (localRSModel != null) {
          paramGraphics.setColor(Color.MAGENTA);
          for (localPolygon : localRSModel.getTriangles())
            paramGraphics.drawPolygon(localPolygon);
        }
      }
    }
    if (Click[3] != 0)
      for (localObject2 : this.ctx.groundItems.getAll()) {
        localRSModel = localObject2.getModel();
        if (localRSModel != null) {
          paramGraphics.setColor(Color.CYAN);
          for (localPolygon : localRSModel.getTriangles())
            paramGraphics.drawPolygon(localPolygon);
        }
      }
  }

  public final void DrawRect(Graphics paramGraphics)
  {
    Color localColor1 = Color.BLACK;
    Color localColor2 = Color.white;
    for (int i = 0; i < WORD_LIST.length; i++) {
      int j = 150;
      paramGraphics.setColor(new Color(localColor1.getRed(), localColor1.getGreen(), localColor1.getBlue(), j));

      if (Click[i] != 0) {
        paramGraphics.setColor(new Color(localColor2.getRed(), localColor2.getGreen(), localColor2.getBlue(), j));
      }
      paramGraphics.fillRect(90 + 80 * i, 3, 80, 12);
      paramGraphics.setColor(Color.white);
      if (Click[i] != 0)
        paramGraphics.setColor(Color.BLACK);
      paramGraphics.drawString(WORD_LIST[i], 90 + 80 * i + 10, 13);
      paramGraphics.setColor(Color.black);
      paramGraphics.drawRect(90 + 80 * i, 3, 80, 12);
    }
  }

  public void mouseClicked(MouseEvent paramMouseEvent)
  {
    for (int i = 0; i < WORD_LIST.length; i++) {
      Rectangle localRectangle = new Rectangle(90 + 80 * i, 3, 80, 12);
      if (localRectangle.contains(paramMouseEvent.getPoint()))
        Click[i] = (Click[i] == 0 ? 1 : false);
    }
  }

  public void mouseEntered(MouseEvent paramMouseEvent)
  {
  }

  public void mouseExited(MouseEvent paramMouseEvent)
  {
  }

  public void mousePressed(MouseEvent paramMouseEvent)
  {
  }

  public void mouseReleased(MouseEvent paramMouseEvent)
  {
  }

  static
  {
    color_map.put(RSObject.Type.BOUNDARY, Color.BLACK);
    color_map.put(RSObject.Type.FLOOR_DECORATION, Color.YELLOW);
    color_map.put(RSObject.Type.INTERACTABLE, Color.WHITE);
    color_map.put(RSObject.Type.WALL_DECORATION, Color.GRAY);

    WORD_LIST = new String[] { "Objects", "Players", "NPCS", "GroundItem" };

    Click = new boolean[] { true, true, true, true };
  }
}